package com.gaussian.property.module.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gaussian.property.module.biz.entity.CheckModule;
import com.gaussian.property.module.biz.entity.CheckTable;
import com.gaussian.property.module.biz.mapper.CheckTableMapper;
import com.gaussian.property.module.biz.service.ICheckModuleService;
import com.gaussian.property.module.biz.service.ICheckTableService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 稽核表 服务实现类
 * </p>
 *
 * @author songqi(13776346982)
 * @since 2024-04-09
 */

public abstract class AbstractCheckTableServiceImpl<M extends BaseMapper<T>, T>  extends ServiceImpl<CheckTableMapper, CheckTable> implements ICheckTableService {

    @Resource
    private ICheckModuleService iCheckModuleService;

    /**
     * 稽核表的所有扣分模块设置的分值
     * @param checkTableId
     * @return
     */
    public double queryTotalMinusModuleScoreInCheckTable(String checkTableId) {
        List<CheckModule> checkModules = queryCheckModuleList(checkTableId);
        return checkModules.stream().filter( t -> t.getIsAllowAddScore() == 0).mapToDouble(CheckModule::getScore).sum();
    }

    /**
     * 根据稽核表id查询稽核模块
     * @param checkTableId
     * @return
     */
    private List<CheckModule> queryCheckModuleList(String checkTableId) {
        LambdaQueryWrapper<CheckModule> queryWrapper = new LambdaQueryWrapper<CheckModule>()
                .eq(CheckModule::getCheckTableId, checkTableId);
        return iCheckModuleService.list(queryWrapper);
    }
}
